/*
 * Copyright (c) 2007-2021 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.xajtfb.bus.api;

import com.github.lvyanyang.annotation.AllowAnonymous;
import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.annotation.RequestJson;
import com.github.lvyanyang.core.BaseController;
import com.github.lvyanyang.core.BoolResult;
import com.github.lvyanyang.core.Const;
import com.xci.xajtfb.bus.entity.WxMember;
import com.xci.xajtfb.bus.model.BuildPhoneCaptchaBody;
import com.xci.xajtfb.bus.model.SendPhoneCaptchaBody;
import com.xci.xajtfb.bus.service.WxMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 小程序用户接口
 * @author 吕艳阳 lvyanyang@xci96716.com
 * @since 2021-03-03 17:35:58
 */
@Api(tags = "小程序用户接口")
@Authorize
@RestController
@RequestMapping(value = "/api/mini/user", produces = Const.PROJSON)
public class WxMemberApiController extends BaseController {
    /** 投诉用户表服务 */
    @Resource private WxMemberService wxmemberService;

    @AllowAnonymous
    @ApiOperation(value = "小程序用户登录")
    @PostMapping("/login")
    public BoolResult<WxMember> login(@RequestJson String openid) {
        return BoolResult.success(wxmemberService.login(openid));
    }

    @AllowAnonymous
    @ApiOperation(value = "小程序用户注册")
    @PostMapping("/register")
    public BoolResult<WxMember> register(@RequestBody WxMember entity) {
        return wxmemberService.register(entity);
    }

    @ApiOperation(value = "小程序用户注销")
    @PostMapping("/logout")
    public BoolResult logout() {
        return BoolResult.success(wxmemberService.logout());
    }

    @AllowAnonymous
    @ApiOperation(value = "生成短信发送验证码")
    @PostMapping(value = "/buildPhoneCaptcha", produces = {Const.PRO_JPEG, Const.PROJSON})
    public void buildPhoneCaptcha(@RequestBody BuildPhoneCaptchaBody body) {
        var model = wxmemberService.buildPhoneCaptcha(body);
        coreService.writeCaptchaToResponse(getResponse(), model);
    }

    @AllowAnonymous
    @ApiOperation(value = "发送手机验证码")
    @PostMapping("/sendPhoneCaptcha")
    public BoolResult sendPhoneCaptcha(@RequestBody SendPhoneCaptchaBody body) {
        return wxmemberService.sendPhoneCaptcha(body);
    }

    // @ApiOperation(value = "更新用户")
    // @PostMapping("/update")
    // public BoolResult<WxMember> update(@RequestBody WxMember entity) {
    //      wxmemberService.update(entity);
    //      return BoolResult.success(wxmemberService.login(entity.getWechatid()));
    // }

    // @ApiOperationSupport(order = 9)
    // @ApiOperation(value = "查询投诉用户表分页列表")
    // //@Authorize(code = "bus.wxmember.select")
    // @PostMapping("/selectPageList")
    // public BoolResult<PageList<Wxmember>> selectPageList(@RequestBody WxmemberFilter filter) {
    //     return BoolResult.success(wxmemberService.selectPageList(filter));
    // }
    //
    // @ApiOperationSupport(order = 10, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    // @ApiOperation(value = "查询投诉用户表列表")
    // //@Authorize(code = "bus.wxmember.select")
    // @PostMapping("/selectList")
    // public BoolResult<List<Wxmember>> selectList(@RequestBody WxmemberFilter filter) {
    //     return BoolResult.success(wxmemberService.selectList(filter));
    // }
    //

}